package org.example.curriculum_design_6_16.mapper;

import org.apache.ibatis.annotations.*;
import org.example.curriculum_design_6_16.entity.pojo.PoliticalPerformance;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

/**
* @author 郑凯
* @description 针对表【political_performance】的数据库操作Mapper
* @createDate 2025-06-16 09:25:48
* @Entity org.example.curriculum_design_6_16.entity.pojo.PoliticalPerformance
*/
@Mapper
public interface PoliticalPerformanceMapper extends BaseMapper<PoliticalPerformance> {
    /**
     * 根据学生ID查询政治表现记录
     * @param studentId 学生ID
     * @return 政治表现列表（按评分降序）
     */
    @Select("SELECT * FROM political_performance WHERE student_id = #{studentId}")
    PoliticalPerformance selectByStudentId(@Param("studentId") String studentId);

    @Select("SELECT * FROM political_performance WHERE student_id = #{studentId} AND academic_year = #{academicYear}")
    PoliticalPerformance selectByStudentIdAndYear(@Param("studentId") String studentId, @Param("academicYear") String academicYear);

    @Select("SELECT * FROM political_performance")
    PoliticalPerformance getAllPoliticalPerformance();

    /**
     * 删除指定学生的所有政治表现记录
     * @param studentId 学生ID
     * @return 删除的记录数
     */
    @Delete("DELETE FROM political_performance WHERE student_id = #{studentId}")
    int deleteByStudentId(@Param("studentId") String studentId);

    /**
     * 更新政治表现评分
     * @param studentId 学号
     * @param newScore 新评分
     * @return 影响的行数
     */
    @Update("UPDATE political_performance SET score = #{newScore} WHERE student_id = #{studentId}")
    int updateScore(
            @Param("studentId") String studentId,
            @Param("newScore") double newScore);

    /**
     * 检查指定学期中学生政治表现基础分是否为0
     * @param studentId 学生ID
     * @return true-基础分为0, false-基础分不为0或记录不存在
     */
    @Select("SELECT COUNT(*) = 1 FROM political_performance " +
            "WHERE student_id = #{studentId} AND base_score = 0")
    boolean isBaseScoreZeroInSemester(
            @Param("studentId") String studentId);
}




